package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.common.ServiceException;
import com.example.demo.dto.UserInfoDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhuchunfeng
 * @Description
 * @Date: 2020/5/13 18:49
 * Copyright (c) 2019 北京新媒传信科技有限公司
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(description = "用户接口", tags = {"会员controller"})
public class UserController {


    @ApiOperation("获取用户接口jenkins")
    @PostMapping("/get")
    public UserInfoDto getUser(@ApiParam(value = "手机号", required = true, example = "18819491302") @RequestParam(value = "phone", required = true) String phone,
                               @ApiParam(value = "验证码", required = true, example = "1234") @RequestParam(value = "captcha", required = true) String captcha) {
        log.info("get a request");
        return new UserInfoDto().setBalance(1).setNewAccount(1).setUnionId("123123123123123");
    }

    @ApiOperation("校验接口jenkins")
    @PostMapping("/add")
    public UserInfoDto addUser(@RequestBody @Validated UserInfoDto userInfoDto) {
        log.info("get a request {}", JSON.toJSONString(userInfoDto));
        return new UserInfoDto().setBalance(1).setNewAccount(1).setUnionId("123123123123123");
    }

    @ApiOperation("异常接口jenkins")
    @GetMapping("/ext")
    public UserInfoDto extUser() {
        throw new ServiceException("自定义异常");
    }

}
